#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>

using namespace std;

void ShellSort(int* a, int n)
{
	int gap = n / 2;
	while (gap > 0)
	{
		for (int i = 0; i < n - gap; i++)
		{
			int end = i;
			int tmp = a[i + gap];

			while (end >= 0 && a[end] > tmp)
			{
				a[end + gap] = a[end];
				end -= gap;
			}
			a[end + gap] = tmp;
		}
		gap = gap / 2;

	}
}

int main()
{
	int a[] = { 9, 2, 3, 5, 4, 6 };
	int n = sizeof(a) / sizeof(a[0]);

	ShellSort(a, n);

	for (int i = 0; i < n; i++)
	{
		cout << a[i] << ' ';
	}
	return 0;
}